<template>
  <!-- 公共客户管理 -->
  <el-container>
    <el-header>
      <div class="left-panel">
        <!-- <el-button
          type="primary"
          icon="el-icon-plus"
          @click="add"
          v-auth-button="['add/customerManagement']"
        ></el-button> -->
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input
            v-model="searchValue.search"
            placeholder="客户名称"
            clearable
          ></el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        row-key="id"
        dataType="listSortBydelete"
        stripe
        @row-dblclick="handleRowDblclick"
      >
        <el-table-column
          fixed
          label="ID"
          prop="id"
          width="60"
        ></el-table-column>
        <el-table-column
          fixed
          label="客户名称"
          prop="customerName"
          min-width="300"
        ></el-table-column>
        <el-table-column label="客户类型" prop="customertypeName" width="100">
          <template #default="scope">
            <!-- 1普通客户  2重要客户  -->
            <p v-if="scope.row.customertype == 1">普通客户</p>
            <p v-if="scope.row.customertype == 2">重要客户</p>
          </template>
        </el-table-column>
        <el-table-column label="联系人" prop="firstcontacter" width="100">
        </el-table-column>
        <el-table-column
          label="联系人号码"
          prop="phone"
          width="120"
        ></el-table-column>
        <el-table-column
          label="客户号码"
          prop="telephone"
          width="150"
        ></el-table-column>
        <el-table-column
          label="地址"
          prop="address"
          min-width="150"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="备注"
          prop="memo"
          min-width="150"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column label="操作" fixed="right" align="right" width="220">
          <template #default="scope">
            <el-button-group>
              <el-popconfirm
                title="确定绑定此客户吗？"
                @confirm="table_bind(scope.row, scope.$index)"
              >
                <template #reference>
                  <el-button
                    text
                    type="primary"
                    size="small"
                    v-auth-button="['bind/customerManagement']"
                    >绑定</el-button
                  >
                </template>
              </el-popconfirm>
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
</template>

<script>
import { queryTypeByDic } from "@/utils/getData"
export default {
  name: "publicCustomer",
  components: {

  },
  data () {
    return {
      dialog: {
        save: false,
        check: false,
        apply: false,
        log: false,
      },
      apiObj: this.$API.customer.publicCustomer.getCustomerList,
      userList: [],
      searchValue: {
        search: null,
      },
      rowData: null,
      userInfo: {},
    }
  },
  mounted () {
    this.userInfo = this.$TOOL.data.get("USER_INFO")
    this.getUserList()
  },
  methods: {


    // 绑定客户
    async table_bind (row) {
      let res = await this.$API.customer.publicCustomer.bindCustomer.post({ id: row.id })
      if (res.code == 200) {
        this.$refs.table.refresh()
        this.$message.success("操作成功")
      } else {
        this.$alert(res.message, "提示", { type: "error" })
      }
    },


    //搜索
    upsearch () {
      this.$refs.table.upData(this.searchValue)
    },


    //本地更新数据
    handleSaveSuccess (data, mode) {
      if (mode == "add") {
        this.$refs.table.refresh()
      } else if (mode == "edit") {
        this.$refs.table.refresh()
      }
    },

    // 双击表格
    handleRowDblclick (row) {
      this.table_show(row)
    },
  },
};
</script>

<style>
</style>
